# -*- coding:utf8 -*-

from flask.views import View

from blog.controller.common import WEB, LOG


class BingImage(View):
    """
        响应前段的请求，返回bing的背景图片相关信息
    """
    def __init__(self):
        self.url = "http://www.bing.com/HPImageArchive.aspx?" \
            "format=js&idx=0&n=1&mkt=cn-CH"

    def dispatch_request(self):
        """

        :rtype: str, 可以被转换成json或者python的dict
        """
        res = WEB.get(self.url)
        if res is not None:
            content = res.read()
            return content
        return u'未知错误'


if __name__ == "__main__":
    bi = BingImage()
    bi.dispatch_request()